﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using Memcached;


public partial class gold_eGoldGgzj : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

            string strIpName = "stock_info";
            string strIP = ConfigurationManager.AppSettings[strIpName];
            string strKey = "EMONEY_DATA_GOLD_AGENCIES_GOODS_SHSZA_DOWN";
            string strKeyUp = "EMONEY_DATA_GOLD_AGENCIES_GOODS_SHSZA_UP";
            Memcached.JSON c = new JSON();
            string strJson = c.GetJsonByKeyIP(strKey, strIP);
            string strJsonUp = c.GetJsonByKeyIP(strKeyUp, strIP);
            List<eGold_GGZJ> data;
            List<eGold_GGZJ> dataup;
            data = (List<eGold_GGZJ>)(Newtonsoft.Json.JsonConvert.DeserializeObject<List<eGold_GGZJ>>(strJson));
            dataup = (List<eGold_GGZJ>)(Newtonsoft.Json.JsonConvert.DeserializeObject<List<eGold_GGZJ>>(strJsonUp));
            //重新排序
            dataup.Sort(delegate(eGold_GGZJ a, eGold_GGZJ b) { return a.BT.CompareTo(b.BT); });  
            data.AddRange(dataup);
            Repeater1.DataSource = data;
            Repeater1.DataBind();


            DateTime dtDate = System.DateTime.Now.Date;
            CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
            CMSModel.eGold_GGZJ gglist;
            try
            {
                gglist = dal.eGold_GGZJ.First(x => x.createdate == dtDate);
                ClientScript.RegisterStartupScript(GetType(), "aa", "document.location='eGoldGetHtml.htm?type=ggzj'", true);
            }
            catch (Exception)
            { 
            
            }

        }
    }


    protected void bt_showgoods_Click(object sender, EventArgs e)
    {
        DateTime dtDate = System.DateTime.Now.Date;
        string strIpName = "stock_info";
        string strIP = ConfigurationManager.AppSettings[strIpName];
        string strKey = "EMONEY_DATA_GOLD_AGENCIES_GOODS_SHSZA_DOWN";
        string strKeyUp = "EMONEY_DATA_GOLD_AGENCIES_GOODS_SHSZA_UP";
        Memcached.JSON c = new JSON();
        string strJson = c.GetJsonByKeyIP(strKey, strIP);
        string strJsonUp = c.GetJsonByKeyIP(strKeyUp, strIP);

        strJson = strJson + "^" + strJsonUp;

        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();

        CMSModel.eGold_GGZJ gglist ;
        try
        {
            gglist = dal.eGold_GGZJ.First(x => x.createdate  == dtDate);
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('数据重复,保存失败!');", true);
        }
        catch (Exception)
        {
            dal.eGold_GGZJ.AddObject(new CMSModel.eGold_GGZJ
            {
                
                list= strJson,
                createdate = System.DateTime.Now.Date
            });
            dal.SaveChanges();
            ClientScript.RegisterStartupScript(GetType(), "aa", "alert('新增成功');document.location='eGoldGetHtml.htm?type=ggzj'", true);
        } 

    }



}